home *** CD-ROM | disk | FTP | other *** search
- /* read specified line from file */
- #include <stdio.h>
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- char c,s[256];
- int i,n,m;
- FILE *fp;
-
- if(argc!=3) { /* print help message */
- printf("getline file number\nreturns the line specified from the file\n");
- printf("\n(C) Rainer Kowallik\n");
- exit(0);
- }
- n=atoi(argv[2]);
- fp=fopen(argv[1],"r");
- if(fp==NULL) { /* trap file open error */
- fprintf(stderr,"can not open file %s\n",argv[1]);
- exit(-1);
- }
- for(m=0;m<n;m++) {
- fgets(s,256,fp); /* read whole string from file */
- if(feof(fp)) { /* trap end of file */
- printf("EOF\n");
- fclose(fp);
- exit(1);
- }
- }
- fclose(fp);
- printf("%s\n",s);
- exit(0);
- }
-
-
-